<template>
    <view>

        <button type="primary" @click="img">button</button>
        <template>
            <u-rate :count="count" v-model="comment.mark"></u-rate>
        </template>
        <u--textarea v-model="comment.comment" placeholder="请输入内容" count ></u--textarea>

        <button @click="goComment">提交评论</button>
    </view>
</template>

<script>
    import Request from '../../utils/request'
    export default {
        data() {
            return{
                count:5,
                comment:{
                    orderId:'',
                    userId:1,
                    comment:'',
                    mark:0,
                },
                uploadFiles:'',
            }
        },
        created(){
            this.comment.orderId=uni.getStorageSync("orderId")
        },
        methods:{
            reload() {
                // 获取当前页面路由 具体请看该函数的实现
                const url = this.getPageUrl(1)
                uni.reLaunch({
                    url,
                    success: () => {
                        console.log('reload触发了!!!!!! url====>' + url)
                    }
                })
            },
            /*提交评论*/
            goComment(){
                uni.uploadFile({
                    url: 'http://localhost:1234/management-mall/leyou.mall/mall-goods-comment/toComment', //仅为示例，非真实的接口地址
                    filePath: this.uploadFiles[0],
                    name: 'file',
                    formData: {
                        "mark":this.comment.mark,
                        "comment":this.comment.comment,
                        "orderId":this.comment.orderId,
                        "userId":this.comment.userId,
                    },
                    success: (uploadFileRes) => {
                        console.log(uploadFileRes.data);
                        if(uploadFileRes.data.success){
                            uni.showToast({
                                icon:'success',
                                title:'评论成功',
                            })
                        }else{
                            uni.showToast({
                                icon:'success',
                                title:'评论成功',
                            })
                        }
                    }
                });
            },
            img(){
                uni.chooseImage({
                    success: (chooseImageRes) => {
                        const tempFilePaths = chooseImageRes.tempFilePaths;
                        this.uploadFiles=tempFilePaths
                    }
                });

                // uni.chooseImage({
                //     success: (chooseImageRes) => {
                //         const tempFilePaths = chooseImageRes.tempFilePaths;
                //         uni.uploadFile({
                //             url: 'http://localhost:1234/management-mall/leyou.mall/mall-goods-comment/toComment', //仅为示例，非真实的接口地址
                //             filePath: tempFilePaths[0],
                //             name: 'file',
                //             formData: {
                //                 'user': 'test'
                //             },
                //             success: (uploadFileRes) => {
                //                 console.log(uploadFileRes.data);
                //             }
                //         });
                //     }
                // });

            }



        }
    }
</script>

<style scoped>

</style>
